\appsection{Algorithms}
\label{appendix:alg}

This appendix contains the algorithms in section~\ref{sec:encoding}
and ~\ref{sec:opt}.







%***********************************************************************
%                     procedure Cost_Init()
%***********************************************************************
\begin{algorithm}[t]
\label{costinit} \LinesNumbered\caption{cost\_init()}

\KwIn{$\Pi^s=(I,F^s,O^s,G)$, $\Phi^c=(V,C,\mu)$, $N$}

%\KwOut{$h(\psi)$}

\For{all $x_{f,0}\in{V}$}{
    set $h(x_{f,0})=0$ if $f \in I$ and $h(x_{f,0})=\infty$ otherwise \;  }

\For{t=0 to $N$}{
    \For{all $x_{o,t}\in{V}$}{
      compute  $h(x_{o,t})$ using \textbf{Definition ~\ref{def:h-action}}\;
    }

    \For{all $x_{f,t+1}\in{V}$}{
       compute  $h(x_{f,t+1})$ using \textbf{Definition ~\ref{def:h-fact}}\;
    }
}

%compute  $h(\psi)$ using \textbf{formula~(\ref{def:h-goal})}\;

\end{algorithm}


%***********************************************************************
%                     procedure Cost_Propagate()
%***********************************************************************
\begin{algorithm}[t]
\label{costprop} \LinesNumbered\caption{cost\_propagate()}

\KwIn{$\Pi^s=(I,F^s,O^s,G)$, $\Phi^c=(V,C,\mu)$}

%\KwOut{$h(\psi)$}

initialize $U$ as a priority queue sorted by $t$\;

\While{ $U\neq{\emptyset}$}{
    get $x$ from $U$, $U \leftarrow U\backslash\{x\}$\;
    \If{$x=x_{o,t}\in{V}$}{

        \lIf{$v_{\psi}(x_{o,t})$=false}{
            $newcost \leftarrow \infty$\;
        }\Else{
        %Q.lv
            %$newcost \leftarrow \max\limits_{{f}\in{pre(a)}}h(x_{f,t})$\;
            compute $newcost$ using \textbf{Definition ~\ref{def:h-action}}\;

        }
        \If{$newcost\neq{h(x_{o,t})}$}{
        %Q.lv
            $h(x_{o,t}) \leftarrow newcost$\;
            \For {all $f\in{add(o)}$}{
                $U \leftarrow U + \{x_{f,t+1}\}$\;
                }
        }
    }\lElse{
        \If{$x=x_{f,t}\in{V}$}{
            \lIf{$v_{\psi}(x_{f,t})$=false}{
                $newcost \leftarrow \infty$\;
            }\lElse{
                compute $newcost$ using \textbf{Definition ~\ref{def:h-fact}}\;
            }
            \If{$newcost\neq{h(x_{f,t})}$}{
            %Q.lv
                $h(x_{f,t}) \leftarrow newcost$\;
                \For {all $o$ such that $f\in{pre(o)}$}{
                        $U \leftarrow U + \{x_{o,t}\}$\;
                }
            }
        }
    }
}

%update $h(\psi)$ for affected $\psi$ using \textbf{formula~(\ref{def:h-goal})}\;

\end{algorithm}
